﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

using Global.Class.Library;

namespace DataTransferObject
{
    public class GCGBClippingCollection : NotifyPropertyChangeObject
    {

        private int gcgbCommandID;
        private int gcgbCommandSerialID;
        private DateTime gcgbCommandDate;

        private int workerNameID;

        private int materialSetID;
        private double remainsQuantity;
        private double quantity;
        private double quantityLoss;

        private int materialSemiID1;
        private double quantityPerSet1;
        private double quantitySemiBad1;
        private double quantitySemiLoss1;
        private double quantitySemiPreviousMinus1;

        private int materialSemiID2;
        private double quantityPerSet2;
        private double quantitySemiBad2;
        private double quantitySemiLoss2;
        private double quantitySemiPreviousMinus2;

        private int materialSemiID3;
        private double quantityPerSet3;
        private double quantitySemiBad3;
        private double quantitySemiLoss3;
        private double quantitySemiPreviousMinus3;                  

        private string remarks;


        public GCGBClippingCollection()
            : this(0, 0, DateTime.Today, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "")
        {
        }

        public GCGBClippingCollection(int gcgbCommandID, int gcgbCommandSerialID, DateTime gcgbCommandDate, int workerNameID, int materialSetID, int materialSemiID1, double quantityPerSet1, double quantitySemiBad1, double quantitySemiLoss1, double quantitySemiPreviousMinus1,
                    int materialSemiID2, double quantityPerSet2, double quantitySemiBad2, double quantitySemiLoss2, double quantitySemiPreviousMinus2,
                    int materialSemiID3, double quantityPerSet3, double quantitySemiBad3, double quantitySemiLoss3, double quantitySemiPreviousMinus3, double remainsQuantity, double quantity, double quantityLoss, string remarks)
        {
            //GlobalDefaultValue.Apply(this);
            this.StopTracking();

            this.GCGBCommandID = gcgbCommandID;
            this.GCGBCommandSerialID = gcgbCommandSerialID;
            this.GCGBCommandDate = gcgbCommandDate;

            this.WorkerNameID = workerNameID;

            this.MaterialSetID = materialSetID;
            this.MaterialSemiID1 = materialSemiID1;
            this.QuantityPerSet1 = quantityPerSet1;
            this.QuantitySemiBad1 = quantitySemiBad1;
            this.QuantitySemiLoss1 = quantitySemiLoss1;
            this.QuantitySemiPreviousMinus1 = quantitySemiPreviousMinus1;

            this.MaterialSemiID2 = materialSemiID2;
            this.QuantityPerSet2 = quantityPerSet2;
            this.QuantitySemiBad2 = quantitySemiBad2;
            this.QuantitySemiLoss2 = quantitySemiLoss2;
            this.QuantitySemiPreviousMinus2 = quantitySemiPreviousMinus2;

            this.MaterialSemiID3 = materialSemiID3;                       
            this.QuantityPerSet3 = quantityPerSet3;
            this.QuantitySemiBad3 = quantitySemiBad3;
            this.QuantitySemiLoss3 = quantitySemiLoss3;
            this.QuantitySemiPreviousMinus3 = quantitySemiPreviousMinus3;

            this.RemainsQuantity = remainsQuantity;
            this.Quantity = quantity;
            this.QuantityLoss = quantityLoss;

            this.Remarks = remarks;

            this.StartTracking();
        }


        #region Properties



        [DefaultValue(0)]
        public int GCGBCommandID
        {
            get { return this.gcgbCommandID; }
            set { ApplyPropertyChange<GCGBClippingCollection, int>(ref this.gcgbCommandID, o => o.GCGBCommandID, value); }
        }

        [DefaultValue(0)]
        public int GCGBCommandSerialID
        {
            get { return this.gcgbCommandSerialID; }
            set { ApplyPropertyChange<GCGBClippingCollection, int>(ref this.gcgbCommandSerialID, o => o.GCGBCommandSerialID, value); }
        }

        [DefaultValue(typeof(DateTime), "01/01/1900")]
        public DateTime GCGBCommandDate
        {
            get { return this.gcgbCommandDate; }
            set { ApplyPropertyChange<GCGBClippingCollection, DateTime>(ref this.gcgbCommandDate, o => o.GCGBCommandDate, value); }
        }


        [DefaultValue(0)]
        public int WorkerNameID
        {
            get { return this.workerNameID; }
            set { ApplyPropertyChange<GCGBClippingCollection, int>(ref this.workerNameID, o => o.WorkerNameID, value); }
        }

        [DefaultValue(0)]
        public int MaterialSetID
        {
            get { return this.materialSetID; }
            set { ApplyPropertyChange<GCGBClippingCollection, int>(ref this.materialSetID, o => o.MaterialSetID, value); }
        }


        [DefaultValue(0)]
        public int MaterialSemiID1
        {
            get { return this.materialSemiID1; }
            set { ApplyPropertyChange<GCGBClippingCollection, int>(ref this.materialSemiID1, o => o.MaterialSemiID1, value); }
        }

        [DefaultValue(0)]
        public double QuantityPerSet1
        {
            get { return this.quantityPerSet1; }
            set
            {
                value = Math.Round(value, GlobalVariables.Round0Quantity);
                ApplyPropertyChange<GCGBClippingCollection, double>(ref this.quantityPerSet1, o => o.QuantityPerSet1, value);
            }
        }

        [DefaultValue(0)]
        public double QuantitySemi1
        {
            get { return this.Quantity * this.QuantityPerSet1; }
        }
       
        [DefaultValue(0)]
        public double QuantitySemiBad1
        {
            get { return this.quantitySemiBad1; }
            set
            {
                value = Math.Round(value, GlobalVariables.Round0Quantity);
                ApplyPropertyChange<GCGBClippingCollection, double>(ref this.quantitySemiBad1, o => o.QuantitySemiBad1, value);
            }
        }

        [DefaultValue(0)]
        public double QuantitySemiLoss1
        {
            get { return this.quantitySemiLoss1; }
            set
            {
                value = Math.Round(value, GlobalVariables.Round0Quantity);
                ApplyPropertyChange<GCGBClippingCollection, double>(ref this.quantitySemiLoss1, o => o.QuantitySemiLoss1, value);
            }
        }

        [DefaultValue(0)]
        public double QuantitySemiPreviousMinus1
        {
            get { return this.quantitySemiPreviousMinus1; }
            set
            {
                value = Math.Round(value, GlobalVariables.Round0Quantity);
                ApplyPropertyChange<GCGBClippingCollection, double>(ref this.quantitySemiPreviousMinus1, o => o.QuantitySemiPreviousMinus1, value);
            }
        }



        [DefaultValue(0)]
        public int MaterialSemiID2
        {
            get { return this.materialSemiID2; }
            set { ApplyPropertyChange<GCGBClippingCollection, int>(ref this.materialSemiID2, o => o.MaterialSemiID2, value); }
        }

        [DefaultValue(0)]
        public double QuantityPerSet2
        {
            get { return this.quantityPerSet2; }
            set
            {
                value = Math.Round(value, GlobalVariables.Round0Quantity);
                ApplyPropertyChange<GCGBClippingCollection, double>(ref this.quantityPerSet2, o => o.QuantityPerSet2, value);
            }
        }

        [DefaultValue(0)]
        public double QuantitySemi2
        {
            get { return this.Quantity * this.QuantityPerSet2; }
        }

        [DefaultValue(0)]
        public double QuantitySemiBad2
        {
            get { return this.quantitySemiBad2; }
            set
            {
                value = Math.Round(value, GlobalVariables.Round0Quantity);
                ApplyPropertyChange<GCGBClippingCollection, double>(ref this.quantitySemiBad2, o => o.QuantitySemiBad2, value);
            }
        }

        [DefaultValue(0)]
        public double QuantitySemiLoss2
        {
            get { return this.quantitySemiLoss2; }
            set
            {
                value = Math.Round(value, GlobalVariables.Round0Quantity); 
                ApplyPropertyChange<GCGBClippingCollection, double>(ref this.quantitySemiLoss2, o => o.QuantitySemiLoss2, value);
            }
        }

        [DefaultValue(0)]
        public double QuantitySemiPreviousMinus2
        {
            get { return this.quantitySemiPreviousMinus2; }
            set
            {
                value = Math.Round(value, GlobalVariables.Round0Quantity);
                ApplyPropertyChange<GCGBClippingCollection, double>(ref this.quantitySemiPreviousMinus2, o => o.QuantitySemiPreviousMinus2, value);
            }
        }

       

        [DefaultValue(0)]
        public int MaterialSemiID3
        {
            get { return this.materialSemiID3; }
            set { ApplyPropertyChange<GCGBClippingCollection, int>(ref this.materialSemiID3, o => o.MaterialSemiID3, value); }
        }
              

        [DefaultValue(0)]
        public double QuantityPerSet3
        {
            get { return this.quantityPerSet3; }
            set
            {
                value = Math.Round(value, GlobalVariables.Round0Quantity);
                ApplyPropertyChange<GCGBClippingCollection, double>(ref this.quantityPerSet3, o => o.QuantityPerSet3, value);
            }
        }

        [DefaultValue(0)]
        public double QuantitySemi3
        {
            get { return this.Quantity * this.QuantityPerSet3; }
        }

        [DefaultValue(0)]
        public double QuantitySemiBad3
        {
            get { return this.quantitySemiBad3; }
            set
            {
                value = Math.Round(value, GlobalVariables.Round0Quantity);
                ApplyPropertyChange<GCGBClippingCollection, double>(ref this.quantitySemiBad3, o => o.QuantitySemiBad3, value);
            }
        }

        [DefaultValue(0)]
        public double QuantitySemiLoss3
        {
            get { return this.quantitySemiLoss3; }
            set
            {
                value = Math.Round(value, GlobalVariables.Round0Quantity);
                ApplyPropertyChange<GCGBClippingCollection, double>(ref this.quantitySemiLoss3, o => o.QuantitySemiLoss3, value);
            }
        }

        [DefaultValue(0)]
        public double QuantitySemiPreviousMinus3
        {
            get { return this.quantitySemiPreviousMinus3; }
            set
            {
                value = Math.Round(value, GlobalVariables.Round0Quantity);
                ApplyPropertyChange<GCGBClippingCollection, double>(ref this.quantitySemiPreviousMinus3, o => o.QuantitySemiPreviousMinus3, value);
            }
        }


        [DefaultValue(0)]
        public double RemainsQuantity
        {
            get { return this.remainsQuantity; }
            set
            {
                value = Math.Round(value, GlobalVariables.Round0Quantity);
                ApplyPropertyChange<GCGBClippingCollection, double>(ref this.remainsQuantity, o => o.RemainsQuantity, value);
            }
        }


        [DefaultValue(0)]
        public double Quantity
        {
            get { return this.quantity; }
            set
            {
                value = Math.Round(value, GlobalVariables.Round0Quantity);
                ApplyPropertyChange<GCGBClippingCollection, double>(ref this.quantity, o => o.Quantity, value);
            }
        }

        [DefaultValue(0)]
        public double QuantityLoss
        {
            get { return this.quantityLoss; }
            set
            {
                value = Math.Round(value, GlobalVariables.Round0Quantity);
                ApplyPropertyChange<GCGBClippingCollection, double>(ref this.quantityLoss, o => o.QuantityLoss, value);
            }
        }



        [DefaultValue("")]
        public string Remarks
        {
            get { return this.remarks; }
            set { ApplyPropertyChange<GCGBClippingCollection, string>(ref this.remarks, o => o.Remarks, value); }
        }

        public GCGBClippingCollection ShallowClone()
        {
            return (GCGBClippingCollection)this.MemberwiseClone();
        }


        #endregion

        protected override System.Collections.Generic.List<ValidationRule> CreateRules()
        {
            List<ValidationRule> validationRules = base.CreateRules();
            validationRules.Add(new SimpleValidationRule("Quantity", "Over remainning quantity.", delegate { return this.Quantity + this.QuantityLoss <= this.RemainsQuantity; }));
            validationRules.Add(new SimpleValidationRule("Quantity", "Please input quantity value.", delegate { return !(this.Quantity <= 0 && this.WorkerNameID > 0); }));
            validationRules.Add(new SimpleValidationRule("WorkerNameID", "Please fill a worker code.", delegate { return !(this.Quantity > 0 && this.WorkerNameID <= 0); }));
            validationRules.Add(new SimpleValidationRule("QuantitySemiLoss1", "Over quantity semi 1.", delegate { return this.QuantitySemiBad1 + this.QuantitySemiLoss1 + this.QuantitySemiPreviousMinus1 <= this.QuantitySemi1; }));
            validationRules.Add(new SimpleValidationRule("QuantitySemiLoss2", "Over quantity semi 2.", delegate { return this.QuantitySemiBad2 + this.QuantitySemiLoss2 + this.QuantitySemiPreviousMinus2 <= this.QuantitySemi2; }));
            validationRules.Add(new SimpleValidationRule("QuantitySemiLoss3", "Over quantity semi 3.", delegate { return this.QuantitySemiBad3 + this.QuantitySemiLoss3 + +this.QuantitySemiPreviousMinus3 <= this.QuantitySemi3; }));

            return validationRules;
        }
    }
}
